EWGL.mesh = function(gl,vert,ind,tex,vertexattr,textureattr,texturesampler){
    this.gl = gl;
    this.vertexattr = vertexattr;
    this.textureattr = textureattr;
    this.texturesampler = texturesampler;
    
    var r = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, r);
    gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray(vert), gl.STATIC_DRAW);
    r.itemSize = 3;
    r.numItems = vert.length/3;
    this.vert = r;
    
    var i = gl.createBuffer();
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, i);
    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedShortArray(ind), gl.STATIC_DRAW);
    i.itemSize = 1;
    i.numItems = ind.length;
    this.ind = i;
    
    var t = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, t);
    gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray(tex), gl.STATIC_DRAW);
    t.itemSize = 2;
    t.numItems = tex.length/2;
    this.tex = t;
    
    return this;
}
EWGL.mesh.prototype.draw = function(texture){
    var gl= this.gl;
    gl.bindBuffer(gl.ARRAY_BUFFER, this.vert);
    gl.vertexAttribPointer(this.vertexattr, this.vert.itemSize, gl.FLOAT, false, 0, 0);
    gl.bindBuffer(gl.ARRAY_BUFFER, this.tex);
    gl.vertexAttribPointer(this.textureattr, this.tex.itemSize, gl.FLOAT, false, 0, 0);
    gl.activeTexture(gl.TEXTURE0);
    gl.bindTexture(gl.TEXTURE_2D, texture);
    gl.uniform1i(this.texturesampler, 0);

    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.ind);
    gl.drawElements(gl.TRIANGLES, this.ind.numItems, gl.UNSIGNED_SHORT, 0);
    return this;
}